﻿#light

open System
open System.Collections.Generic
open System.Reflection
open TypeRepository
open AstTypes
open System.Collections.Generic

(*
let createDictionaryFromDefaultProp(obj:System.Object) = 
    let objType = obj.GetType()
    let defaultPropNameOpt = TypeProvider.MapDefaultProperty(objType.Name)
    let compModifDictionary = new Dictionary<string,ComponentModification>()
    match defaultPropNameOpt with
    | Some defaultPropName ->
        let defaultProp = objType.GetProperty(defaultPropName)
        let defaultPropType = defaultProp.PropertyType
        let defaultPropInnerType = defaultPropType.GetGenericArguments().[0]
        let defaultPropVal = defaultProp.GetValue(obj,[||]) :?> IList<_>        
        for defaultPropValItem in defaultPropVal do
            let modifName,modif = createComponentModification(defaultPropValItem,defaultPropInnerType)
            compModifDictionary.Add(modifName,modif)
        defaultPropName,compModifDictionary
    | None ->
        "",compModifDictionary

let createComponentModification(obj:System.Object) = 
    let mappingSource = (obj.GetType().GetCustomAttributes(typeof<MappingAttribute>,false).[0] :?> MappingAttribute ).Source    
    let compModif = new ComponentModification()
    // we don't implement compound component references like obj.comp.comp etc.
    compModif._compReference = new ComponentReference([ComponentReferenceParts.Name(mappingSource)])
    // now resolve default attributes -> create nested component modification
    let defaultPropertyNameOpt = TypeProvider.MapDefaultProperty(objType.Name)
    let defaultPropName =
         match defaultPropertyNameOpt with
         | Some defPropName ->
                    
    
    
    
    mappingSource,new compModif

let createComponentModificationDictionary(obj:System.Object) = 
    
    // add here mapping for non-default properties
    compModifDictionary



let DemapAnnotation(obj:System.Object) = 
    let compModif = createComponentModificationDictionary(obj)
    let classModif = new ClassModification()
    classModif._compRedef <- new Dictionary<string,ComponentRedefinition>()
    classModif._classRedef <- new Dictionary<string,ClassRedefinition>()
    classModif._compModif <- compModif
    classModif
    
  *)  